﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TouchSocket.Core;
using TouchSocket.Http.WebSockets;
using TouchSocket.Sockets;

namespace Kang.Test.WPF.FTP
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            txt_log.Document = new FlowDocument();
        }

        private void btn_start_Click(object sender, RoutedEventArgs e)
        {
            TcpService service = new TcpService();

            var config = new TouchSocketConfig();
            config.SetListenIPHosts(new []{ new IPHost("tcp://127.0.0.1:21") })//同时监听两个地址
                .SetDataHandlingAdapter(() =>
                {
                    //return new TerminatorPackageAdapter(Environment.NewLine);//亦或者省略\r\n，但此时调用方不能高速调用，会粘包
                    return new NormalDataHandlingAdapter();//亦或者省略\r\n，但此时调用方不能高速调用，会粘包
                })
                .ConfigureContainer(a =>//容器的配置顺序应该在最前面
                {
                    a.AddConsoleLogger();//添加一个控制台日志注入（注意：在maui中控制台日志不可用）
                })
                .ConfigurePlugins(a =>
                {
                    a.Add<FtpCommandLinePlugin>();
                });
            service.Setup(config);//启动
            service.Start();//启动

            Console.WriteLine("服务器成功启动。");
        }
    }
}
